package javaroke.servlets;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javaroke.excepcion.DAOExcepcion;
import javaroke.modelo.Sala;
import javaroke.modelo.Local;
import javaroke.negocio.GestionSala;

/**
 * Servlet implementation class RegistrarSala
 */
@WebServlet("/RegistrarSala")
public class RegistrarSala extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RegistrarSala() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
					
		try{
		
			GestionSala negCan = new GestionSala();
			
			Sala vo = new Sala();
						
			Integer a = Integer.parseInt(request.getParameter("idsala"));
			String  b = request.getParameter("nombre");
			Integer c = Integer.parseInt(request.getParameter("capacidad"));
			String  d = request.getParameter("descripcion");			
			String  e = request.getParameter("eLog");
			Integer f = Integer.parseInt(request.getParameter("idLocal"));	
			
			Local loc = new Local();
			
			vo.setNombre(b);
			vo.setCapacidad(c);
			vo.setDescripcion(d);
			vo.seteLog(e);
			loc.setIdlocal(f);
			vo.setLocal(loc);
			
			try {
				negCan.insertar(vo);
								
				request.setAttribute("MENSAJE", "Se registro la sala correctamente.");
				
			} catch (DAOExcepcion e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
				request.setAttribute("MENSAJE", e1.getMessage());
			}
		
			
		} catch (IllegalArgumentException e2) {
			// TODO Auto-generated catch block
			e2.printStackTrace();
			request.setAttribute("MENSAJE", "ERROR, Falta llenar campos o tipo de variable no soportada: -" + e2.getMessage() + "-");
	}
		
			RequestDispatcher rd = request
					.getRequestDispatcher("/jsp/RegistrarSala.jsp");
			rd.forward(request, response);
		
		
				
		}
}

		
	



